remove_front(X, L) :- append(X, _, L).
remove_back(X, L) :- append(_, X, L).
my_sublist(X, L) :- remove_front(S, L), remove_back(X, S).

member_rec(M, [M|_]) :- true .
member_rec(M, [H|T]) :- ( member_rec(M,T) ; member_rec(M,H) ) ; (my_sublist(M,[H|T]) ) .

is_ingredient(I) :- ingredients(N, S), member(I, S).
is_ingredient_stem(I) :- ingredients_stem(N, S), member(I, S).
is_meal(I) :- ingredients(N, S), I == N.
is_meal_stem(I) :- meal_stem(N, S), I == S.
get_meal_by_stem(I, N) :- meal_stem(N, S), I == S.

is_part_of(I) :- (is_part_of_ingredient(I)  ; is_part_of_meal(I)) .
is_part_of_ingredient(I) :- (ingredients(N, S), member_rec(I,S), \+ (member(I,S))).
is_part_of_ingredient_stem(I) :- (ingredients_stem(N, S), member_rec(I,S), \+ (member(I,S))).
is_part_of_meal(I) :-  ( ingredients(N,S), member_rec(I,N), I\==N ).
is_part_of_meal_stem(I) :-  ( meal_stem(N,S), member_rec(I,S), I\==S ).

what_can_i_do(Ingredient, Meal) :-  (ingredients(Meal ,List),member(Ingredient ,List)).
what_can_i_do([Ingredient|Tail], Meal) :-  (ingredients(Meal ,List), member(Meal ,List)), what_can_i_do(Tail, Meal).

what_can_i_do_stem(Ingredient, Meal) :-  (ingredients_stem(Meal ,List),member(Ingredient ,List)).
what_can_i_do_stem([Ingredient|Tail], Meal) :-  (ingredients_stem(Meal ,List), member(Ingredient ,List)), what_can_i_do_stem(Tail, Meal).


%%what_is_missing(I,D, Missing, Recipe) :-  ingredients(D,L), deletelist(L,I, Missing), recipe(D,Recipe).
